[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 rename()                Rename a File or Directory

 #include   <stdio.h>

 int        rename(oldname,newname);
 const char *oldname;                    Pointer to old name
 const char *newname;                    Pointer to new name

    rename() renames a file or directory, changing the name from
    'oldname' to 'newname'.

       Returns:     0, if successful or a -1 value if an error occurs. On
                    error, 'errno' (defined in <errno.h>) is set to:

                    EACCES:    'newname' already exists; or an invalid
                               path was specified
                    ENOENT:    'oldname' not found
                    ENOTSAM:   not the same device

         Notes:     'oldname' must be the name of an existing file or
                    directory. 'newname' cannot already exist.
                    Directories can only be renamed. They cannot be
                    moved.

   Portability:     MS-DOS only.

   -------------------------------- Example ---------------------------------

    This example changes the file name 'sales.dat' to 'oldsales.dat', in
    effect moving it to a backup directory.

           #include <stdio.h>

           main()
           {
              if ((rename("sales.dat","c:\\bakup\\oldsales.dat")) == 0)
                printf("last week's sales file moved to a backup directory");
           }


See Also: creat() fopen() open()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson